package websocket.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import websocket.test.pojo.WebSocketMessage;
import websocket.test.servers.WebSocketServer;

@RestController
public class SendController {
    @Autowired
    private WebSocketServer webSocketServer;
    /**
     * 接收一个请求 传递一个参数userId
     * 目标给这个用户id的客户端推送ws消息
     */
    @GetMapping("/send")
    public String send(Integer userId,String msg){
        WebSocketMessage<String> message=new WebSocketMessage<>();
        message.setState(200);
        message.setMessage("成功");
        message.setData(msg);
        //给这个userId的ws客户端推送消息 msg
        webSocketServer.sendMsgToUser(userId,message);
        return "success";
    }
}
